<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<title>登录 - 宿舍后台管理系统</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<link rel="stylesheet" type="text/css" href="/static/v5/css/materialdesignicons.min.css">
<link rel="stylesheet" type="text/css" href="/static/v5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/v5/css/animate.min.css">
<link rel="stylesheet" type="text/css" href="/static/v5/css/style.min.css">
<style>
</style>
</head>

<body class="bg-white overflow-x-hidden">
<div class="row bg-white vh-100">
  <div class="col-md-6 col-lg-7 col-xl-8 d-none d-md-block" style="background-image: url(/static/v5/images/login-bg-1.jpg); background-size: cover;">

    <div class="d-flex vh-100">
      <div class="p-5 align-self-end">
        <img src="/static/v5/images/logo.png" alt="...">
        <br><br><br>
        <p class="text-white">这是一套关于企业宿舍管理系统，可以用于管理员工住宿，水电抄表，水电费计算系统。</p>
      </div>
    </div>

  </div>

  <div class="col-md-6 col-lg-5 col-xl-4 align-self-center">
    <div class="p-5">
      <div class="text-center">
        <a href="/"> <img alt="light year admin" src="/static/v5/images/logo-sidebar.png"> </a>
      </div>
      <p class="text-center text-muted"><small>请使用您的账号登录系统</small></p>

      <form method="post" class="signin-form needs-validation" novalidate>
        <div class="mb-3">
          <label for="name">用户名</label>
          <input type="text" class="form-control" id="name" name="name" placeholder="请输入您的用户名" required>
        </div>

        <div class="mb-3">
          <label for="password">密码</label>
          <input type="password" class="form-control" id="password" name="password" placeholder="请输入您的密码" required>
        </div>

        <div class="mb-3">
          <div class="form-check">
            <input type="checkbox" class="form-check-input" id="rememberme">
            <label class="form-check-label not-user-select" for="rememberme">5天内自动登录</label>
          </div>
        </div>

        <div class="mb-3 d-grid">
          <button class="btn btn-primary" type="submit">立即登录</button>
        </div>
      </form>
      <p class="text-center text-muted mt-3">Copyright © 2022 <a target="_blank" href="http://www.kdstudio.cc">狂盗工作室</a>. All right reserved</p>
    </div>
  </div>
</div>
<script type="text/javascript" src="/static/v5/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/v5/js/popper.min.js"></script>
<script type="text/javascript" src="/static/v5/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/v5/js/lyear-loading.js"></script>
<script type="text/javascript" src="/static/v5/js/bootstrap-notify.min.js"></script>
    <script>
        // 处理表单提交
        $('.signin-form').on('submit', function(event) {
            // 如果表单验证失败，阻止默认提交并标记为验证失败
            if ($(this)[0].checkValidity() === false) {
                event.preventDefault();
                event.stopPropagation();
                $(this).addClass('was-validated');
                return false;  // 阻止表单提交
            }

            var $data = $(this).serialize();

            // 发送 AJAX 请求
            $.post($(this).attr('action'), $data, function(response) {
                // 根据后端返回的 success 字段判断是否登录成功
                if (response.success) {
                    $.notify({
                        message: '登录成功，页面即将跳转~',
                    },{
                        type: 'success',
                        placement: {
                            from: 'top',
                            align: 'right'
                        },
                        z_index: 10800,
                        delay: 1500,
                        animate: {
                            enter: 'animate__animated animate__fadeInUp',
                            exit: 'animate__animated animate__fadeOutDown'
                        }
                    });
                    // 登录成功后，延迟跳转到 admin 页面
                    setTimeout(function () {
                        location.href = '/admin';  // 修改为需要跳转的页面
                    }, 1500);
                } else {
                    $.notify({
                        message: '登录失败，错误原因：' + response.msg,
                    },{
                        type: 'danger',
                        placement: {
                            from: 'top',
                            align: 'right'
                        },
                        z_index: 10800,
                        delay: 1500,
                        animate: {
                            enter: 'animate__animated animate__shakeX',
                            exit: 'animate__animated animate__fadeOutDown'
                        }
                    });
                }
            }).fail(function () {
                $.notify({
                    message: '服务器错误',
                },{
                    type: 'danger',
                    placement: {
                        from: 'top',
                        align: 'right'
                    },
                    z_index: 10800,
                    delay: 1500,
                    animate: {
                        enter: 'animate__animated animate__shakeX',
                        exit: 'animate__animated animate__fadeOutDown'
                    }
                });
            });

            return false;  // 阻止表单的默认提交
        });
    </script>

</body>
</html>